package com.huarui.purchaseOrder.action;

import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

import org.ewaf.framework.action.BaseAction;
import com.huarui.purchaseOrder.model.PurOrSaleOrder;
import com.huarui.purchaseOrder.model.PurOrSaleOrderDetail;
import com.huarui.purchaseOrder.service.PurchaseOrderService;
import com.huarui.util.FuncUtil;

public class PurchaseUpdateAction extends BaseAction{

	public static String MESS = "mess";
	private static final long serialVersionUID = 8632418515230431994L;
//	private Logger logger = Logger.getLogger(PurchaseUpdateAction.class);
	private PurchaseOrderService purchaseOrderService;
	
	private String pur;
	private String add;
	private String all;
	private String update;

	private Map<String, Object> mesMap;
	
	
	public String getPur() {
		return pur;
	}



	public void setPur(String pur) {
		this.pur = pur;
	}



	public String getAdd() {
		return add;
	}



	public void setAdd(String add) {
		this.add = add;
	}



	public String getAll() {
		return all;
	}



	public void setAll(String all) {
		this.all = all;
	}



	public String getUpdate() {
		return update;
	}



	public void setUpdate(String update) {
		this.update = update;
	}



	public Map<String, Object> getMesMap() {
		return mesMap;
	}



	public void setMesMap(Map<String, Object> mesMap) {
		this.mesMap = mesMap;
	}



	public void setPurchaseOrderService(PurchaseOrderService purchaseOrderService) {
		this.purchaseOrderService = purchaseOrderService;
	}



	@SuppressWarnings("unchecked")
	private String updatePurAndDetails() {
		JSONObject jo_pur = JSONObject.fromObject(pur);
		FuncUtil.removeNullValue(jo_pur);
		PurOrSaleOrder order = (PurOrSaleOrder) JSONObject.toBean(jo_pur, PurOrSaleOrder.class);
		JSONArray ja_update = JSONArray.fromObject(update);
		FuncUtil.removeNullValue(ja_update);
		List<PurOrSaleOrderDetail> _update = (List<PurOrSaleOrderDetail>) JSONArray.toCollection(ja_update, PurOrSaleOrderDetail.class);
		JSONArray ja_add = JSONArray.fromObject(add);
		FuncUtil.removeNullValue(ja_add);
		List<PurOrSaleOrderDetail> _add = (List<PurOrSaleOrderDetail>) JSONArray.toCollection(ja_add, PurOrSaleOrderDetail.class);
		JSONArray ja_all = JSONArray.fromObject(all);
		List<Integer> _all = (List<Integer>) JSONArray.toCollection(ja_all);
		
		mesMap = purchaseOrderService.updatePurAndDetails(order, _update, _add, _all);
		
		return MESS;
	}
	
	/**
	 * 在线订单修改
	 * @return
	 */
	public String updateOnlinePurAndDetails() {
		return this.updatePurAndDetails();
	}
	
	/**
	 * 非在线订单修改
	 * @return
	 */
	public String updateNotOnlinePurAndDetails() {
		return this.updatePurAndDetails();
	}
	
	/**
	 * 在线修改并提交
	 * @return
	 */
	public String updateToSubmitOnlinePurAndDetails() {
		return this.updatePurAndDetails();
	}
	
	/**
	 * 非在线修改并提交
	 * @return
	 */
	public String updateToSubmitNotOnlinePurAndDetails() {
		return this.updatePurAndDetails();
	}
}
